using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
	/// <summary>
	/// Strongly-typed collection for the CxFile class.
	/// </summary>
    [Serializable]
	public partial class CxFileCollection : ActiveList<CxFile, CxFileCollection>
	{	   
		public CxFileCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>CxFileCollection</returns>
		public CxFileCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                CxFile o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the CX_File table.
	/// </summary>
	[Serializable]
	public partial class CxFile : ActiveRecord<CxFile>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public CxFile()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public CxFile(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public CxFile(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public CxFile(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CX_File", TableType.Table, DataService.GetInstance("CXDB"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarFileID = new TableSchema.TableColumn(schema);
				colvarFileID.ColumnName = "FileID";
				colvarFileID.DataType = DbType.Guid;
				colvarFileID.MaxLength = 0;
				colvarFileID.AutoIncrement = false;
				colvarFileID.IsNullable = false;
				colvarFileID.IsPrimaryKey = true;
				colvarFileID.IsForeignKey = false;
				colvarFileID.IsReadOnly = false;
				colvarFileID.DefaultSetting = @"";
				colvarFileID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFileID);
				
				TableSchema.TableColumn colvarGuid = new TableSchema.TableColumn(schema);
				colvarGuid.ColumnName = "Guid";
				colvarGuid.DataType = DbType.Guid;
				colvarGuid.MaxLength = 0;
				colvarGuid.AutoIncrement = false;
				colvarGuid.IsNullable = true;
				colvarGuid.IsPrimaryKey = false;
				colvarGuid.IsForeignKey = false;
				colvarGuid.IsReadOnly = false;
				colvarGuid.DefaultSetting = @"";
				colvarGuid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarGuid);
				
				TableSchema.TableColumn colvarFilename = new TableSchema.TableColumn(schema);
				colvarFilename.ColumnName = "filename";
				colvarFilename.DataType = DbType.String;
				colvarFilename.MaxLength = 500;
				colvarFilename.AutoIncrement = false;
				colvarFilename.IsNullable = true;
				colvarFilename.IsPrimaryKey = false;
				colvarFilename.IsForeignKey = false;
				colvarFilename.IsReadOnly = false;
				colvarFilename.DefaultSetting = @"";
				colvarFilename.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFilename);
				
				TableSchema.TableColumn colvarFilesize = new TableSchema.TableColumn(schema);
				colvarFilesize.ColumnName = "filesize";
				colvarFilesize.DataType = DbType.Double;
				colvarFilesize.MaxLength = 0;
				colvarFilesize.AutoIncrement = false;
				colvarFilesize.IsNullable = true;
				colvarFilesize.IsPrimaryKey = false;
				colvarFilesize.IsForeignKey = false;
				colvarFilesize.IsReadOnly = false;
				colvarFilesize.DefaultSetting = @"";
				colvarFilesize.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFilesize);
				
				TableSchema.TableColumn colvarFiletype = new TableSchema.TableColumn(schema);
				colvarFiletype.ColumnName = "filetype";
				colvarFiletype.DataType = DbType.String;
				colvarFiletype.MaxLength = 50;
				colvarFiletype.AutoIncrement = false;
				colvarFiletype.IsNullable = true;
				colvarFiletype.IsPrimaryKey = false;
				colvarFiletype.IsForeignKey = false;
				colvarFiletype.IsReadOnly = false;
				colvarFiletype.DefaultSetting = @"";
				colvarFiletype.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFiletype);
				
				TableSchema.TableColumn colvarFilepath = new TableSchema.TableColumn(schema);
				colvarFilepath.ColumnName = "filepath";
				colvarFilepath.DataType = DbType.String;
				colvarFilepath.MaxLength = 500;
				colvarFilepath.AutoIncrement = false;
				colvarFilepath.IsNullable = true;
				colvarFilepath.IsPrimaryKey = false;
				colvarFilepath.IsForeignKey = false;
				colvarFilepath.IsReadOnly = false;
				colvarFilepath.DefaultSetting = @"";
				colvarFilepath.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFilepath);
				
				TableSchema.TableColumn colvarInTime = new TableSchema.TableColumn(schema);
				colvarInTime.ColumnName = "inTime";
				colvarInTime.DataType = DbType.DateTime;
				colvarInTime.MaxLength = 0;
				colvarInTime.AutoIncrement = false;
				colvarInTime.IsNullable = true;
				colvarInTime.IsPrimaryKey = false;
				colvarInTime.IsForeignKey = false;
				colvarInTime.IsReadOnly = false;
				
						colvarInTime.DefaultSetting = @"(getdate())";
				colvarInTime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInTime);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["CXDB"].AddSchema("CX_File",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("FileID")]
		[Bindable(true)]
		public Guid FileID 
		{
			get { return GetColumnValue<Guid>(Columns.FileID); }
			set { SetColumnValue(Columns.FileID, value); }
		}
		  
		[XmlAttribute("Guid")]
		[Bindable(true)]
		public Guid? Guid 
		{
			get { return GetColumnValue<Guid?>(Columns.Guid); }
			set { SetColumnValue(Columns.Guid, value); }
		}
		  
		[XmlAttribute("Filename")]
		[Bindable(true)]
		public string Filename 
		{
			get { return GetColumnValue<string>(Columns.Filename); }
			set { SetColumnValue(Columns.Filename, value); }
		}
		  
		[XmlAttribute("Filesize")]
		[Bindable(true)]
		public double? Filesize 
		{
			get { return GetColumnValue<double?>(Columns.Filesize); }
			set { SetColumnValue(Columns.Filesize, value); }
		}
		  
		[XmlAttribute("Filetype")]
		[Bindable(true)]
		public string Filetype 
		{
			get { return GetColumnValue<string>(Columns.Filetype); }
			set { SetColumnValue(Columns.Filetype, value); }
		}
		  
		[XmlAttribute("Filepath")]
		[Bindable(true)]
		public string Filepath 
		{
			get { return GetColumnValue<string>(Columns.Filepath); }
			set { SetColumnValue(Columns.Filepath, value); }
		}
		  
		[XmlAttribute("InTime")]
		[Bindable(true)]
		public DateTime? InTime 
		{
			get { return GetColumnValue<DateTime?>(Columns.InTime); }
			set { SetColumnValue(Columns.InTime, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varFileID,Guid? varGuid,string varFilename,double? varFilesize,string varFiletype,string varFilepath,DateTime? varInTime)
		{
			CxFile item = new CxFile();
			
			item.FileID = varFileID;
			
			item.Guid = varGuid;
			
			item.Filename = varFilename;
			
			item.Filesize = varFilesize;
			
			item.Filetype = varFiletype;
			
			item.Filepath = varFilepath;
			
			item.InTime = varInTime;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varFileID,Guid? varGuid,string varFilename,double? varFilesize,string varFiletype,string varFilepath,DateTime? varInTime)
		{
			CxFile item = new CxFile();
			
				item.FileID = varFileID;
			
				item.Guid = varGuid;
			
				item.Filename = varFilename;
			
				item.Filesize = varFilesize;
			
				item.Filetype = varFiletype;
			
				item.Filepath = varFilepath;
			
				item.InTime = varInTime;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn FileIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn GuidColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn FilenameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn FilesizeColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn FiletypeColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn FilepathColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn InTimeColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string FileID = @"FileID";
			 public static string Guid = @"Guid";
			 public static string Filename = @"filename";
			 public static string Filesize = @"filesize";
			 public static string Filetype = @"filetype";
			 public static string Filepath = @"filepath";
			 public static string InTime = @"inTime";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
